import type { BasicColumn, FormSchema } from '@/components/Table';
import { render,geneBillNo } from '/@/utils/common/renderUtils';
import { JVxeColumn, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
import { dateUtil } from '/@/utils/dateUtil';
import { ref } from 'vue';

export const searchFormSchema: FormSchema[] = [];

export const columns: BasicColumn[] = [
  {
    title: '单据编号',
    dataIndex: 'billNo',
    align: 'center',
  },
  {
    title: '单据日期',
    dataIndex: 'billDate',
    align: 'center',
    customRender: render.renderDate,
  },
  {
    title: '总计金额	',
    dataIndex: 'totalAmount',
    align: 'center',
  },
  {
    title: '折扣率',
    dataIndex: 'discountRate',
    align: 'center',
  },
  {
    title: '折扣金额',
    dataIndex: 'discountAmount',
    align: 'center',
  },
  {
    title: '打折后金额',
    dataIndex: 'discountLastAmount',
    align: 'center',
  },
  {
    title: '欠款金额',
    dataIndex: 'arrearsAmount',
    align: 'center',
  },
  {
    title: '其他费用',
    dataIndex: 'otherAmount',
    align: 'center',
  },
  {
    title: '已付定金',
    dataIndex: 'deposit',
    align: 'center',
  },
  {
    title: '附件',
    dataIndex: 'fileId',
    align: 'center',
  },
  {
    title: '账户',
    dataIndex: 'multipleAccount',
    align: 'center',
  },
  {
    title: '备注',
    dataIndex: 'remark',
    align: 'center',
  },
  {
    title: '入库状态',
    dataIndex: 'inStockStatus',
    align: 'center',
  },
  {
    title: '审核状态',
    dataIndex: 'status',
    align: 'center',
  },
  {
    title: '关联单据',
    dataIndex: 'otherReceipt',
    align: 'center',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    align: 'center',
    customRender: render.renderDate,
  },
  {
    title: '修改时间',
    dataIndex: 'updateTime',
    align: 'center',
    customRender: render.renderDate,
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '编号',
    field: 'id',
    show: false,
    component: 'Input',
  },
  {
    label: '供应商',
    field: 'supplierId',
    colProps: {
      span: 6,
    },
    component: 'JSelectSupplierByType',
    componentProps: {
      isRadioSelection:true,
    },
  },
  {
    label: '单据日期',
    field: 'billDate',
    defaultValue: dateUtil(),
    colProps: {
      span: 6,
    },
    component: 'DatePicker',
  },
  {
    label: '单据编号',
    field: 'billNo',
    colProps: {
      span: 6,
    },
    defaultValue:geneBillNo("CGDD"),
    component: 'Input',
  },
  {
    label: '订单明细',
    field: 'items',
    colProps: {
      span: 24,
    },
    component: 'Input',
    slot: 'itemsSlot',
  },
  {
    label: '总计金额	',
    field: 'totalAmount',
    componentProps: {
      disabled: true,
    },
    colProps: {
      span: 6,
    },
    component: 'InputNumber',
  },
  /*  {
    label: '折扣率(%)',
    field: 'discountRate',
    colProps: {
      span: 6,
    },
    component: 'InputNumber',
  }, */
  {
    label: '已付定金',
    field: 'deposit',
    colProps: {
      span: 6,
    },
    component: 'InputNumber',
  },
  {
    label: '折扣金额',
    field: 'discountAmount',
    colProps: {
      span: 6,
    },
    component: 'InputNumber',
  },
  {
    label: '打折后金额',
    field: 'discountLastAmount',
    componentProps: {
      disabled: true,
    },
    colProps: {
      span: 6,
    },
    component: 'InputNumber',
  },

  {
    label: '付款账户',
    field: 'multipleAccount',
    colProps: {
      span: 6,
    },
    component: 'JDictSelectTag',
    componentProps: {
      type: 'select',
    },
  },
  {
    label: '备注',
    field: 'remark',
    colProps: {
      span: 24,
    },
    component: 'InputTextArea',
  },
  {
    label: '附件',
    field: 'fileId',
    colProps: {
      span: 24,
    },
    component: 'JUpload',
    componentProps: {
      bizPath: 'demo/purchaseprebill',
    },
  },
];

export const itemsSchema = ref<JVxeColumn[]>([
  /* {
    title: 'id',
    key: 'id',
    align: 'center',
    type: 'hidden',
  },
  {
    title: 'skuId',
    key: 'skuId',
    align: 'center',
    type: 'hidden',
  }, */
  {
    title: '商品名称',
    key: 'title',
    align: 'center',
    type: 'normal',
  },
  {
    title: '商品编码',
    key: 'spuCode',
    align: 'center',
    type: 'normal',
  },
  {
    title: '货号',
    key: 'skuCode',
    align: 'center',
    type: 'normal',
  },
  {
    title: '规格型号',
    key: 'specNameStr',
    align: 'center',
    type: 'normal',
  },
  {
    title: '仓库',
    key: 'stockRoomId',
    align: 'center',
    type: JVxeTypes.select,
    dictCode: 'sys_user,username,id',
  },
  {
    title: '数量',
    key: 'skuNum',
    align: 'center',
    type: 'input-number',
    defaultValue: 1,
    statistics: ['sum'],
  },
  {
    title: '采购单价',
    key: 'costPrice',
    align: 'center',
    type: 'input-number',
  },
  {
    title: '总价',
    key: 'totalAmount',
    align: 'center',
    type: 'normal',
    statistics: ['sum'],
  },
  {
    title: '交货日期',
    key: 'deliveryDate',
    align: 'center',
    type: 'date',
  },
  {
    title: '税率',
    key: 'taxRate',
    align: 'center',
    type: 'input-number',
  },
  {
    title: '税额',
    key: 'taxAmount',
    align: 'center',
    type: 'input-number',
  },
  {
    title: '价税合计（含税金额）',
    key: 'taxIncludedAmount',
    align: 'center',
    type: 'normal',
  },
  {
    title: '备注',
    key: 'remark',
    align: 'center',
    type: 'input',
  },
  {
    title: '操作',
    key: 'action',
    type: JVxeTypes.slot,
    fixed: 'right',
    minWidth: 100,
    align: 'center',
    slotName: 'tableAction',
  },
]);
